etc: improve laserjet 6 rear tray clip
[clinton/3d-models.git] / ble arcade controller / arcade-box.scad
... / ...
CommitLineData
1// arcade controller thing
2// Copyright (c) 2017 Clinton Ebadi <clinton@unknownlamer.org>
3// GPLv3 or (at your option) any later version
4// .. insert license text here ...
5
6// todo:
7// - hinge
8// - screw holes + captive nut to mount
9// - internal mount for mcu and battery
10// - hole for usb panel mount
11// - bevel lid
12
13// maybe/wishlist:
14// - wire routing clips on panel?
15// - buttons on side for pinball?
16// - vent under mcu/battery?
17// - slant panel toward player?
18
19// bugs:
20// - hinge is not aligned -- either male arm length or connector placement is wrong
21
22use <obiscad/bcube.scad>
23use <obiscad/bevel.scad>
24use <obiscad/attach.scad>
25use <joints.scad>
26
27// PREVIEW
28preview();
29
30module preview () {
31 rotate ([-10, 0, 0]) translate ([0, 0, box_depth+20]) panel ();
32 case ();
33 for (i = [2 ,4]) translate ([panel_width+hinge_joint_width*i, 0, 0]) hinge_male ();
34
35}
36
37// CONFIGURATION
38
39panel_width = 250;
40panel_height = 130;
41panel_bevel = 2; // fixme: calculate based on box_base_thickness?
42
43box_depth = 80;
44box_wall = 2;
45box_base_thickness = 5;
46
47$button_d = 30; // I think this should be special
48
49joystick_width = 85;
50joystick_height = 40;
51
52hinge_arm_width = 6;
53hinge_arm_thickness = 6;
54hinge_arm_length = 50;
55
56// size of block to cut female connector from
57hinge_base_size = [hinge_arm_width * 2, hinge_arm_thickness * 2, hinge_arm_thickness * 2];
58
59hinge_x_offset = 15; // distance from side of case
60
61
62// gunk that should be elsewhere...
63// bcube parameters, clean up
64cr = box_wall*2;
65cres = 0;
66
67// switch to hide panel in previews
68_hide_panel = false;
69
70// PANEL COMPONENTS
71
72module button (bezel = $button_d+4) {
73 circle (d=$button_d);
74 %circle(d=bezel);
75}
76
77module joystick () {
78 bolt_d = 8;
79 center_hole_d = 24;
80
81 for (x = [-joystick_width/2, joystick_width/2], y = [-joystick_height/2, joystick_height/2]) {
82 translate ([x, y, 0]) circle (d=bolt_d); // need slot instead
83 }
84 circle (d=center_hole_d);
85 %square ([joystick_width, joystick_height], center=true); // not right...
86}
87
88
89// CASE
90
91module case_base (width=panel_width, height=panel_height, d=box_base_thickness) {
92 bcube([width, height, d], cr, cres);
93}
94
95module case_walls () {
96 difference () {
97 union () {
98 difference() {
99 bcube([panel_width, panel_height, box_depth-box_base_thickness], cr, cres);
100 bcube([panel_width-box_wall*2, panel_height-box_wall*2, box_depth+1], cr, cres); // FIXME: does this accidentally cut some of the bottom out?
101 }
102 attach (case_connector_wall ([panel_width/2-hinge_x_offset, -box_wall+0.01, box_depth/2]), hinge_connector_back (h=hinge_base_size[2]+(hinge_arm_thickness+panel_bevel)/2)) hinge_female_base (support=true);
103 attach (case_connector_wall ([-panel_width/2+hinge_x_offset, -box_wall+0.01, box_depth/2]), hinge_connector_back (h=hinge_base_size[2]+(hinge_arm_thickness+panel_bevel)/2)) hinge_female_base (support=true);
104 }
105 attach (case_connector_wall ([panel_width/2-hinge_x_offset, -box_wall+0.01, box_depth/2]), hinge_connector_back (h=hinge_base_size[2]+(hinge_arm_thickness+panel_bevel)/2)) hinge_female_cut ();
106 attach (case_connector_wall ([-panel_width/2+hinge_x_offset, -box_wall+0.01, box_depth/2]), hinge_connector_back (h=hinge_base_size[2]+(hinge_arm_thickness+panel_bevel)/2)) hinge_female_cut ();
107 }
108 %connector (case_connector_wall ([panel_width/2-hinge_x_offset, -box_wall+0.01, box_depth/2]));
109}
110
111module case () {
112 case_base ();
113 translate ([0, 0, box_depth/2]) case_walls ();
114}
115
116
117// todo:
118// specify which wall (rear, front, left, right). vector addition may help...
119// offset from center of wall, as vector (and use vector subtraction!)
120// optional: inside/outside
121CASE_WALL_BACK = [0, panel_height/2, -box_base_thickness/2];
122
123function case_connector_wall (offset=[0,0,0], wall=CASE_WALL_BACK) = [ wall + offset, [0, -1, 0], 0 ];
124
125// HINGE
126
127// hinge todo:
128// allow override of global base dimensions
129
130// maybe: add connector for pin to socket so that can easily be test
131// fit in software for a nicer preview
132
133function hinge_connector_back (th=hinge_arm_thickness*2, h=hinge_base_size[2]) = [ [0, th/2, h/2], [0,1, 0], 0 ];
134function hinge_connector_bottom (th=hinge_arm_thickness*2, h=hinge_base_size[2]) = [ [0, 0, -h/2], [0, 0, 1], 0 ];
135
136// todo:
137// gusset support underneath (with argument to toggle)
138
139module hinge_female_base (support=false) {
140// %connector (hinge_connector_back ());
141// %connector (hinge_connector_bottom ());
142 color ([0.5,0.3,0.1, 0.3]) cube (hinge_base_size, center=true);
143
144 if (support) {
145 corner = [ [ 0, hinge_base_size[1]/2, -hinge_base_size[2]/2], [ 0, -1, -1 ], 0];
146 base_a = [ [0, hinge_base_size[1]/2, -hinge_base_size[2]/2], [1, 0, 0], 0];
147 connector (corner);
148 connector (base_a);
149 // fixme: calculate actual radius
150 color ([0.5,0.7,0.1, 0.3]) bconcave_corner_attach(base_a, corner , l=hinge_base_size[1], cr=hinge_base_size[0],cres=0, ext_corner=false, th=0);
151 }
152}
153
154module hinge_female_cut () {
155 joint_male_negative (male_joint_width=hinge_arm_width,
156 male_joint_thickness=hinge_arm_thickness,
157 forward_rom=90,
158 backward_rom=90,
159 male_joint_height=hinge_arm_length);
160}
161
162module hinge_female (support=false) {
163 difference () {
164 hinge_female_base (support);
165 hinge_female_cut ();
166 }
167}
168
169module hinge_male () {
170 for (i=[0,1]) mirror ([0, i, 0]) translate ([0, -hinge_arm_length/4, 0])
171 joint_male (male_joint_width=hinge_arm_width,
172 male_joint_thickness=hinge_arm_thickness,
173 male_joint_height=hinge_arm_length/2,
174 side=true);
175}
176
177
178// PANEL
179
180// fixme: when attachment axis is [0, 0, -1] something makes the math
181// go funky and the connector is facing upward, adding very slight y
182// misalignment "fixes" it...
183PANEL_BOTTOM = [ [ 0, 0, -box_base_thickness/2+0.01 ], [ 0, 0.000000000001, -1 ] ];
184PANEL_TOP = [ [ 0, 0, box_base_thickness/2-0.01 ], [ 0, 0, 1 ] ];
185
186function panel_connector (offset=[0,0,0], wall=PANEL_BOTTOM) = [ wall[0]+offset, wall[1], 0 ];
187
188module panel () {
189 difference () {
190 union () {
191 // bevel
192 translate ([0, 0, panel_bevel/2]) {
193 case_base (d=box_base_thickness-panel_bevel);
194 }
195 case_base (width=panel_width-box_wall*2-0.1, height=panel_height-box_wall*2-0.1);
196 }
197 if (!_hide_panel) {
198 linear_extrude (box_base_thickness*2,center=true) panel_layout ();
199 }
200 }
201
202 attach (panel_connector (offset=[panel_width/2-hinge_x_offset, panel_height/2-hinge_arm_length, 0]),
203 hinge_connector_bottom ()) hinge_female ();
204 attach (panel_connector (offset=[-panel_width/2+hinge_x_offset, panel_height/2-hinge_arm_length, 0]),
205 hinge_connector_bottom ()) hinge_female ();
206}
207
208module panel_attach (position, angle=0) {
209 x = position[0];
210 y = position[1];
211 c1 = [ [x, y, box_base_thickness/2], [0,0,1], angle ];
212 a1 = [ [0,0, 0], [0,0,0], 0 ];
213// %connector (c1); // fixme: don't use 2d for layout
214 attach (c1, a1) children ();
215}
216
217// panel layout inspired by the Neo Geo layout
218module panel_layout () {
219 translate ([-panel_width/2 + 40, 0, 0]) {
220 panel_attach ([0, 0], 90) joystick ();
221
222 // p1, coin (floating off in the distance...)
223 translate ([140, 0, 0]) {
224 $button_d=16;
225 for (x = [0, $button_d+10]) {
226 panel_attach ([x, 42]) button ();
227 }
228 }
229
230 // a, b, c, d
231 translate ([60, -20, 0]) {
232 panel_attach ([0, 0]) button ();
233 for (i = [ 1 : 3 ]) {
234 panel_attach ([i*($button_d+10)-10, $button_d]) button ();
235 }
236 }
237 }
238}